<template>
    <rui-page :defines="defines">
        <!-- 查询条件 -->
        <rui-query :label-width="120"
                   ref="businessSelectConfForm"
                   :query="queryData"
                   :query-rows="searchFormOptions">
        </rui-query>
        <Row>
            <Button type="primary" icon="ios-add" @click="jumpTo()">新增</Button>
            <Button @click="refresh()" icon="ios-refresh">刷新</Button>
        </Row>
        <rui-table
            :defineId="'businessScenariosDefines'"
            :fixedRight="['action']"
            :showIndex="false"
            :select="false"
            :columns="businessSelectConfColumns"
            :slots="[{key:'action',slot:'action'}]"
            @loadDatas="queryData"
            ref-query="businessSelectConfForm"
            ref="businessSelectConfTable"
        >
            <template slot="action" slot-scope="{ row }">
                <Button @click="editRow(row)" size="small" type="primary">编辑
                </Button>
                <Button @click="deleteRow(row)" size="small" type="error">删除
                </Button>
            </template>
        </rui-table>
    </rui-page>
</template>

<script>
    import {
        getBusinessConfInfo,
        deleteBusinessConfInfo
    } from "../../../api/apply/business-scenarios/businessScenariosApi";
    import businessScenariosDefines from "../../../api/apply/business-scenarios/businessScenariosDefines";

    export default {
        mounted() {
            let queryData = {
                pageNumber: 1,
                pageSize: 10,
                condition: {businessName: ""},
            }
            this.queryData(queryData);
        },
        computed: {
            defines() {
                return [{id: "businessScenariosDefines", fields: businessScenariosDefines}];
            }
        },
        data() {
            return {
                editModalVisible: false,
                name: 'businessSelectConfList',
                //查询条件所用字段
                searchFormOptions: [
                    {
                        isGroup: false,
                        defineId: "businessScenariosDefines",
                        fields: ["businessName", "businessType", "carType"],
                    },
                ],
                //详细列表信息显示所用字段
                businessSelectConfColumns: ['action', 'businessName', 'businessType', 'carType', 'carNature', 'operateWay', 'affiliatedWay', 'carPurpose'],
            }
        },
        methods: {
            jumpTo() {
                let param = {
                    isAdd: true
                };
                this.afs.newTab(this, 'projects/afs-core-business/pages/apply/business-scenarios/businessSelectConf', '业务场景选择配置', 'ios-add',
                    param, 'businessSelectConfListAdd' + param.isAdd, [], true);
            },
            //查询方法
            queryData(queryData) {
                getBusinessConfInfo(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.businessSelectConfTable.updateTableData(records, total);
                    }
                });
            },
            //刷新
            refresh() {
                this.$refs['businessSelectConfTable'].reloadData();
            },
            //编辑
            editRow(row) {
                let param = {
                    id: row.id,
                    isAdd: false
                };
                this.afs.newTab(this, 'projects/afs-core-business/pages/apply/business-scenarios/businessSelectConf', '业务场景选择配置', 'ios-add',
                    param, 'businessSelectConfListEdit' + param.id, [], true);
            },
            //删除
            deleteRow(row) {
                this.$Modal.confirm({
                    title: "确认删除?",
                    onOk: () => {
                        deleteBusinessConfInfo(row).then(res => {
                            if (res.code === "0000") {
                                this.$Message.success("删除成功");
                                this.refresh();
                            }
                        });
                    }
                });
            },
        },
    }
</script>
